package com.example.demo.controller;

import com.example.demo.model.Student;
import com.example.demo.service.StudentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @RestController 注解后，可以使后面的方法不需要显式加@ResponseBody注解
 */
@RestController
@RequestMapping("/stu")
public class StudentController {
    @Autowired
    private StudentService studentService;
    @RequestMapping("/selectAll")
    public List<Student> selectAll(){

        return studentService.selectAll();
    }
    @RequestMapping("/getByKey")
    public Student getByKey(@RequestParam("id") Integer id){
        return studentService.selectByPrimaryKey(id);
    }
    @RequestMapping("/insert")
    public List<Student> insert(Student student){
        studentService.insert(student);
        return studentService.selectAll();
    }
    @RequestMapping("/update")
    public List<Student> update(Student student){
        studentService.updateByPrimaryKey(student);
        return studentService.selectAll();
    }
    @RequestMapping("/delete")
    public int delete(@RequestParam("id") Integer id){
        return studentService.deleteByPrimaryKey(id);
    }
}
